﻿@{
    Layout = null;
}

<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/layer/skin/layer.css" rel="stylesheet" />
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/layui/layui.js"></script>


<script>
    $(function (){
        $.ajax({
            url:"/Approve/GetMaterial",
            type:"get",
            dataType:"json",
            success:function(obj){
                console.info(obj)
                $(obj).each(function(){
                    $("#typeName").append("<option value="+this.id+">"+this.name+"</option>")
                })
            }
        })
    })
    function fh(){
        window.parent.location.reload();
        var index = parent.layer.getFrameIndex(window.name);parent.layer.close(index);
    }
    function AddWare() {

        if ($("#name").val() == "") {
            $("#sname").html("物资名称不能为空！")
            return;
        }if ($("#name").val() != "") {
            $("#sname").html("*")
        }
        if ($("#specifications").val() == "") {
            $("#sspecifications").html("规格不能为空！")
            return;
        }if ($("#specifications").val() != "") {
            $("#sspecifications").html("*")
        }
        if ($("#origin").val() == "") {
            $("#sorigin").html("产地不能为空！")
            return;
        }if ($("#origin").val() != "") {
            $("#sorigin").html("*")
        }
        if ($("#num").val() <=-1) {
            $("#snum").html("数量不能小于0！")
            return;
        }if ($("#num").val() >=0 ) {
            $("#snum").html("*")
        }
        if ($("#price").val() == "") {
            $("#price").html("单价不能为空！")
            return;
        }if ($("#price").val() != "") {
            $("#price").html("*")
        }
        var formData=new FormData();
            formData.append("Name",$("#name").val());
            formData.append("ProcurementTypeId",$("#typeName").val());
            formData.append("Material",$("#material").val());
            formData.append("Specifications",$("#specifications").val());
            formData.append("Origin",$("#origin").val());
            formData.append("Num",$("#num").val());
            formData.append("Price",$("#price").val());
            formData.append("Remarks",$("#remarks").val());
            formData.append("PurchaseAmount",$("#purchaseAmount").val());
            formData.append("Registrant",$("#registrant").val());
            formData.append("PaymentMethod",$("[name=paymentMethod]:checked").val());

        $.ajax({
            url: "/Gathering/Add",
            type: "post",
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            dataType:"json",
            success: function (obj) {
                if (obj > 0) {
                    alert("添加成功");
                    fh();
                    location.href="/Gathering/GatheringIndex"
                }
                else {
                    layer.msg("添加失败")
                }
            }
        })
    }
</script>


<h3 style="text-align:center">添加物资入库</h3>
<table style="text-align:center" align="center">
    <tr>
        <td>外协单位：</td>
        <td><input id="outsourcing" type="text" /><span id="soutsourcing" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>结算方式：</td>
        <td>
            <input type="radio" name="settlementMethod" value="微信支付">微信支付</input>
            <input type="radio" name="settlementMethod" value="支付宝" checked>支付宝</input>
            <input type="radio" name="settlementMethod" value="线下支付">线下支付</input>
        </td>
    </tr>
    <tr>
        <td>吨位(m3)：</td>
        <td><input id="tonna" /></td>
    </tr>
    <tr>
        <td>单价(元/m3)</td>
        <td><input id="price" /></td>
    </tr>
    <tr>
        <td>金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额：</td>
        <td><input id="sumPrice" /><span id="sumPrice" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>业务日期：</td>
        <td><input id="businessTIme" /><span id="businessTIme" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>经&nbsp;&nbsp;办&nbsp;&nbsp;人：</td>
        <td><input id="handler" type="number" /><span id="handler" style="color:red">*</span></td>
    </tr>
    <tr>
        <td>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
        <td><input id="remarks" /></td>
    </tr>
    <tr>
        <td colspan="2"><input type="button" value="添加" onclick="AddWare()" /></td>
    </tr>
</table>
